import request from '@/utils/request'

/**
 * 获取部门树
 */
export function getDeptTree() {
  return request({
    url: '/dept/tree',
    method: 'get'
  })
}

/**
 * 添加部门
 * @param data
 */
export function addDept(data) {
  let dept = { parentid: data.parentid, name: data.label }
  return request({
    url: '/dept',
    method: 'post',
    data: JSON.stringify(dept)
  })
}

/**
 * 获取部门信息
 * @param id
 */
export function getDeptById(id) {
  return request({
    url: '/dept/' + id,
    method: 'get'
  })
}

/**
 * 更新部门信息
 * @param data
 */
export function updateDeptById(data) {
  let dept = {
    id: data.id,
    name: data.label,
    parentid: (data.parentid!==null && data.parentid!=='' && data.parentid!==undefined) ? data.parentid : 0
  }
  return request({
    url: '/dept',
    method: 'put',
    data: JSON.stringify(dept)
  })
}

/**
 * 删除部门
 */
export function deleteDeptById(id) {
  return request({
    url: '/dept/' + id,
    method: 'delete'
  })
}

